﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stone.Library.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class DoubleInt
    {
        public int lowInt { get; set; }
        public int highInt { get; set; }
        public DoubleInt(string double_string)
        {
            string[] tmp = double_string.Split('-');
            lowInt = int.Parse(tmp[0]);
            highInt = int.Parse(tmp[1]);
        }

        /// <summary>
        /// 比较两个时间段的是否重合,
        /// <example>
        /// DoubleInt di=new DoubleInt("11530-11730")   lowint
        /// bool b=di.compare(new DoubleInt("11630-11830")) lowtmp
        /// </example>
        /// <remarks>
        /// 假设有a1-a2时间段和b1-b2时间段
        /// 首先比较a1,b1;得出比较后的时间b1,即b1>a1,然后b1和a2比较
        /// 如果b1>=a2,没有重合段. 否则有.
        /// </remarks>
        /// </summary>
        /// <param name="newOne"></param>
        /// <returns>如果重合返回true;没有重合返回false</returns>
        public bool compare(string newOne)
        {
            bool b = false;
            string[] tmp=newOne.Split('-');
            int lowtmp=int.Parse(tmp[0]);
            int hightmp=int.Parse(tmp[1]);
            if (lowInt == lowtmp) b = true;
            else if (lowInt > lowtmp && lowInt < hightmp) b = true;
            else if (lowtmp > lowInt && lowtmp < highInt) b = true;
            return b;
        }

        #region 重载==,!=操作符
        public static bool operator ==(DoubleInt n1, DoubleInt n2)
        {
            if (n1.lowInt == n2.lowInt && n1.highInt == n2.highInt)
                return true;
            else
                return false;
        }

        public static bool operator !=(DoubleInt n1, DoubleInt n2)
        {
            if (n1.lowInt != n2.lowInt || n1.highInt != n2.highInt)
                return true;
            else
                return false;
        }
        #endregion
    }
}
